package com.huiquan.medicine.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.huiquan.analysis.domain.User;
import com.huiquan.framework.base.EnhancedBaseDao;
import com.huiquan.icd.domain.IcdDiseaseImage;
import com.huiquan.inspection.domain.TestingClass;
import com.huiquan.medicine.entity.BasDrug;
import com.ibatis.sqlmap.client.SqlMapClient;

/**
 * 药品 DAO
 *
 * @author leo
 * @time 2017年4月5日 下午5:52:12
 */
@Repository
public class DrugDao extends EnhancedBaseDao<BasDrug> {

	@Resource(name = "sqlMapClient")
	private SqlMapClient sqlMapClient;

	public static final String space = "BAS_DRUG.";

	public DrugDao() {
		super(space);
	}
	public void addImage(Map<String, String> param) {
		this.insert(space + "INSERT", param, sqlMapClient);
	}
	
	public int retrieveSizeByName(String name) {
		Map<String, Object> param = new HashMap<>();
		param.put("imageName", "%"+name+"%");
		Integer size = (Integer) this.object(space + "RETRIEVE_SIZE_BY_NAME", param, sqlMapClient);
		return size == null ? 0 : size;
	}
	
	
	
	public void updateDisable(Long id, Integer current, User user) {
		Map<String, Object> param = new HashMap<>();
		param.put("id", id);
		param.put("current", current);
		param.put("userId", user.getUserId());
		param.put("userName", user.getRealName());
		this.update(space + "UPDATE_DISABLE", param, sqlMapClient);
	}
	public void addBatch(List<IcdDiseaseImage> list){
		this.insert(space + "INSERT_BATCH", list, sqlMapClient);
	}
	public void deleteById(String id){
		Map<String, Object> param = new HashMap<>();
		param.put("id", id);
		this.insert(space + "DELETE_BY_ID", param, sqlMapClient);
	}
	public IcdDiseaseImage retrieveByName(String name) {
		Map<String, Object> param = new HashMap<>();
		param.put("name", name);
		return (IcdDiseaseImage) this.object(space + "RETRIEVE_BY_NAME", param, sqlMapClient);
	}
	
	/**
	 * 找到比当前rank值大的第一个检验大类
	 * 
	 * @param rank
	 * @return
	 */
	public TestingClass selectFirstHighByRank(int rank) {
		return (TestingClass) this.object(space + "SELECT_FIRST_HIGH_BY_RANK", rank, sqlMapClient);
	}

	/**
	 * 找到比当前rank值小的第一个检验大类
	 * 
	 * @param rank
	 * @return
	 */
	public TestingClass selectFirstLowByRank(int rank) {
		return (TestingClass) this.object(space + "SELECT_FIRST_LOW_BY_RANK", rank, sqlMapClient);
	}

}
